package com.oocl.zero.task0710.random;

public class MyRandom {
	public static int getRandom(int from, int to,double percent,int target) {
		percent = percent/100;
		double random = Math.random();
		if(random<percent){
			return target;
		}else{
			return getRandomExcept(from,to,target);
		}
	}
	
	private static int getRandomExcept(int from, int to, int target) {
		double random = Math.random();
		int rs=(int)(random*(to-from+1)) + (from);
		return (rs!=target) ? rs : getRandomExcept( from,  to, target);
	}

	public static void main(String[] args) {
		int max=10000;
		int count=0;
		int from=1;
		int to=100;
		int target=37;
		double percent=20;
		
		for(int i=0;i<max;i++){
			if( getRandom(from,to,percent,target)==target ){
				++count;
			}
		}
//		System.out.println( count*1.0/max );
		double rsPercent=count*1.0/max;
		System.out.println( Math.abs( rsPercent-percent/100 ) < 0.01 );
	}
}
